﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;

namespace DAL
{
   public class EstadoWrapper : BaseWrapper, IWrapper<Estado>
    {
        public List<Estado> GetAll()
        {
            throw new NotImplementedException();
        }

        public Estado GetById(int id)
        {
            Estado EEntity = new Estado();
            SqlConnection cn = new SqlConnection(ConnectionString());
            SqlCommand cmd = new SqlCommand("SP_ESTADO_GETBYID", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@IDESTADO", id);
            try
            {
                cn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    EEntity.SIGLA = dr["SIGLA"].ToString();
                    EEntity.IDESTADO = int.Parse(dr["IDESTADO"].ToString());
                }
            }
            catch (SqlException ex)
            {
                Messages += "Erro \n";
                Messages += ex.Message.ToString();
                Logs.MENSAGEM = Messages;
                Logs.TIPOLOG = "Leitura de dados";
                LOGsWrapper LogsWrapper = new LOGsWrapper();
                LogsWrapper.Insert(Logs);
            }
            finally
            {
                cn.Close();
            }
            return EEntity;

        }

        public bool Insert(Estado entity)
        {
            throw new NotImplementedException();
        }

        public bool Update(Estado entity)
        {
            throw new NotImplementedException();
        }

        public bool Delete(Estado entity)
        {
            throw new NotImplementedException();
        }
    }
}
